package com.hl233.framework.utils;

import java.util.Random;

/**
 * 随机生产验证码
 *
 * @author 张振强15065206763
 * @create 2024-09-05
 */
public class RandomCode {

    public static String code(int n) {

        Random rd = new Random();
        String code = "";
        for (int i = 0; i < n; i++) {
            int type = rd.nextInt(3);  //验证码的三种类型
            switch (type) {
                case 0: //数字
                    code += rd.nextInt(10);
                    break;
                case 1: //大写字母
                    char ch1 = (char) (rd.nextInt(26) + 65);  //数据的强制转换
                    code += ch1;
                    break;
                case 2: //小写字母
                    char ch2 = (char) (rd.nextInt(26) + 97);  //数据的强制转换
                    code += ch2;
                    break;
            }
        }
        return code;
    }
}
